package alan.springboot2x.zkConfig.controller;

import alan.springboot2x.zkConfig.config.TestConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: Alan
 * @date: 2021/3/21 22:10
 */
@RestController
public class ConfigController {

    @Autowired
    private Environment environment;

    @Autowired
    private TestConfig testConfig;

    @Value("${test.username:1}")
    private String username;

    @GetMapping("getConfig")
    public String getConfig(){
        System.out.println(testConfig.hashCode() + "");
        System.out.println("testConfig username" + testConfig.getUsername());
        System.out.println(this.hashCode() + "");
        String testUsername = environment.getProperty("test.username");
        System.out.println("testUsername = "+testUsername);
        System.out.println("@value:username = "+username);
        return testUsername;
    }
}
